/**
 * 力扣剑指offer05:替换空格
 */

public class replaceSpace {
    public static void main(String[] args) {
        
        System.out.println(replaceSpace("We are happy").toString());
    }
    public static String replaceSpace(String s) {
        StringBuffer stringBuffer = new StringBuffer();
        for (Character ch: s.toCharArray()) {
            if (ch == ' '){
                stringBuffer.append("%20");
            }else {
                stringBuffer.append(ch);
            }
        }
        // for(Character c : s.toCharArray())
        // {
        //     if(c == ' ') {
        //         stringBuffer.append("%20");
        //     }
        //     else {
        //         stringBuffer.append(c);
        //     }
        // }
        return stringBuffer.toString();
    }
}
